home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Essentials / Technical.Notes / AIIe / TN.AIIE.004 < prev    next >
Encoding:
Text File  |  1989-04-22  |  16.7 KB  |  328 lines  |  [TEXT/pdos]

  1. Apple II
  2. Technical Notes
  3. _____________________________________________________________________________
  4.                                                   Developer Technical Support
  5.  
  6.  
  7. Apple IIe
  8. #4:    RDY Line
  9.  
  10. Revised by:    Glenn A. Baxter                                  November 1988
  11. Written by:    Peter Baum                                           July 1984
  12.  
  13. This Technical Note describes an input signal to the 6502 microprocessor 
  14. called the RDY line.
  15. _____________________________________________________________________________
  16.  
  17.  
  18. Using the RDY Line on the Apple IIe and Apple ][+
  19.  
  20. Though the 6502 was one of the first commercially successful microprocessors 
  21. sold, the designers had foresight to include some very useful functions.  
  22. Because many early peripherals products were very slow devices, a 
  23. microprocessor could not read from the device directly.  To connect these slow 
  24. devices onto the Apple peripheral bus so the 6502 can read data from them 
  25. requires either buffering the device or slowing down the processor.  Though 
  26. most people would try to buffer the device, sometimes it is not feasible.  
  27. When buffering is not possible, a peripheral device can pull the RDY line to 
  28. slow down the processor long enough to read a byte.  This technique can be 
  29. used by slow devices to communicate with the 6502.
  30.  
  31. The RDY line allows a peripheral card to halt the microprocessor during read 
  32. operations (opcode, operand, or data fetches--reads ) with the output address 
  33. lines reflecting the current address being fetched.  If a peripheral device 
  34. cannot get data on the bus fast enough to meet the setup time of the 6502, 
  35. then the peripheral card can pull the RDY line low and tell the 6502 to wait.  
  36. This cannot be done during a 6502 write cycle because the 6502 does not wait 
  37. during writes.
  38.  
  39. For the 6502 to read a valid data byte from a peripheral card, the card has 
  40. about 800 ns from the time the addresses are valid to put the data on the bus.  
  41. The data must be setup on the bus within approximately 400 ns from the time 
  42. that the I/O STROBE, I/O SELECT, or DEVICE SELECT signal on the peripheral 
  43. slot goes true.  If a device pulls the RDY line low for one clock cycle, the 
  44. device will have approximately 1.4 µs, instead of the 400 ns, to put out valid 
  45. data.  The RDY line can be pulled low for more than one cycle--in fact, there 
  46. is no limit.  A device that takes 100 µs to send data can just hold the RDY 
  47. line low for 100 cycles.  Hence, this technique will allow any slower device 
  48. to get on the bus and send data to the 6502.
  49.  
  50. This is a bit different than DMA on the Apple IIs.  DMA actually prevents the 
  51. CPU from receiving a clock signal, whereas the RDY line is actually a function 
  52. of the processor.  In Apple II DMA, the 6502 CPU will die after approximately 
  53. 15 clocks because it depends on the clock to refresh its internal registers.  
  54. (The 6502 is dynamic, whereas the 65C02 is static, and therefore not affected 
  55. by the absence of clock information).  In the case of the RDY line, the CPU is 
  56. internally told to just not complete its bus cycle until RDY is de-asserted.  
  57. This is a similar concept to DTACK on the Motorola 68000 series CPUs.
  58.  
  59. The RDY line is typically pulled low during PH1, but the specification sheets 
  60. for the 6502 show that it can be pulled anytime before the last 200 ns of PH2.  
  61. The PH2 line is not used by the Apple II and is an unused output from the 
  62. 6502.  It is basically the same as the PH0 line with a little delay.  Before I 
  63. explain when to use (or not use, in some cases) the RDY line, let us first 
  64. look at some timing diagrams of the Apple system.
  65.  
  66. Figure 1 shows the relationship between the 6502 and Apple IIe and Apple ][+.  
  67. The timing specifications have been adjusted to reflect the signals as they 
  68. are seen from the peripheral slots.  For example the 6502 (1 MHz) 
  69. specification guarantees that the address bus will be valid within 225 ns from 
  70. PH2 out.  But the peripheral slots do not see these address lines directly.  
  71. Instead, the address lines go through a buffer and then out to the peripheral 
  72. slots.  This routing adds a maximum delay of 13 ns in the Apple ][ and 18 ns 
  73. in the Apple IIe.  The timing diagrams will show, in the case of an Apple ][, 
  74. that the address bus will be valid to the peripheral slots within 238 ns 
  75. (225+13) of the PH2 falling edge.
  76.  
  77. The major differences in timing between the Apple ][+ and the Apple IIe are 
  78. due to the processor.  The Apple ][ uses a 1 MHz 6502, while the Apple IIe 
  79. uses a 6502A, which is a 2 MHz part.  This does not mean that the system clock 
  80. in the Apple IIe runs any faster, only that the 6502A is capable of running 
  81. faster.  This difference results in better timing margins.  For example, the 
  82. address and data buses are set up faster in the Apple IIe by the 6502A than 
  83. the 6502 sets them up in the Apple ][.  (This was done because the custom 
  84. chips in the Apple IIe are slower than the discrete logic in the Apple ][, and 
  85. the 6502A was needed to compensate).
  86.  
  87. A peripheral card which uses the RDY line can only be used under certain 
  88. circumstances.  Because pulling the RDY line low halts the processor, any 
  89. program with a software timing loop may not work properly.  These programs 
  90. assume that each instruction will take a fixed amount of time, which is not 
  91. true when the processor stops in the middle of an instruction.  An Apple II 
  92. Disk is an example of a peripheral which requires timing loops and may not run 
  93. properly if the RDY line is used.
  94.  
  95.              Apple ][1 MHz 6502            Apple IIe 2 MHz 6502A
  96. Symbol    Minimum         Maximum         Minimum         Maximum
  97. T02- *    15              50+20 (LS08)    15              50+5 (S02)
  98. T02+ *    30              80+15 (LS08)    30              80+5 (S02)
  99. Tads                      225+13 (8T97)                   140+18 (LS244)
  100. Trwh      30                              30
  101. Tdevsel-                  96 (3 x LS138)                  65 (LS154+LS138)
  102. Tiosel-                   64 (2 x LS138)                  38 (LS138)
  103. Tiostb-                   32 (LS138)                      15 (LS10)
  104. Tdevsel+                  18 (LS138)                      30 (LS154)
  105. Tiosel+                   36 (2 x LS138)                  18 (LS138)
  106. Tiostb+                   18 (LS138)                      15 (LS10)
  107. Tdsu      100+17 (8T28)**                 50+12 (LS245)
  108. Thr       10                              10
  109. Trs ***   200                             200
  110.  
  111. (All times are given in nanoseconds (ns).)
  112. *     load = 100 pf.
  113. **    The RFI versions of the Apple ][+, revisions A through D 
  114.       motherboards, use an 8304 instead an 8T28.
  115. ***   The RDY line must never change states within Trs to end of 02.
  116.  
  117.              Table 1-Timing Specifications for Figure 1
  118.                                                               
  119. ___________                          ________________________
  120. Apple 0o   |________________________|       CPU phase        |_______________
  121.  
  122.  
  123. Apple 01    ________________________                          _______________
  124. ___________|     Video phase        |________________________|
  125.  
  126.  
  127. Q3          _______________          _______________          _______________
  128. ___________|               |________|               |________|
  129.  
  130.            |TO2- |                  |TO2+ |                  |TO2- |
  131.  
  132. _________________                          ________________________
  133. 02 out of 6502*  |________________________|                        |_________
  134.  
  135.                  |  Tads     |                              Trwh ->|  |
  136.  
  137. ___________________________  __________________________________________  ____
  138. R/W & ADDR                 \/          valid addresses                 \/
  139. ___________________________/\__________________________________________/\____
  140. as seen from slots
  141.                                     |Tdevsel- |              |Tdevsel+|
  142.  
  143. DEVICE SELECT
  144. ______________________________________________                          _____
  145. as seen from slots                            |________________________|
  146.  
  147.                                     |Tiosel-|                |Tiosel+|
  148.  
  149. I/O SELECT
  150. ____________________________________________                          _______
  151. as seen from slots                          |________________________|
  152.  
  153.                                     |Tiostb-|                |Tiostb+|
  154.  
  155. I/O STROBE
  156. ____________________________________________                          _______
  157. as seen from slots                          |________________________|
  158.  
  159.                                                       Tdsu ->|      ||<- Thr
  160.  
  161. DATA                                                         ________
  162. ____________________________________________________________/ valid  \_______
  163. from slots                                                  \________/
  164.  
  165.                                                  |     Trs          |
  166.  
  167. _______________________________________________  ____________________  ______
  168. RDY                                            \/ don't change state \/
  169. _______________________________________________/\____________________/\______
  170.  
  171. * - 02 is an output signal from the 6502 which is not used by the Apple.
  172.     It is a delayed 0o.
  173.  
  174.           Figure 1 - Timing Signals As Seen From the Peripheral Slots
  175.  
  176.  
  177. Table 1 lists three different type of numbers.  If a number is by itself, then 
  178. it is just the corresponding 6502 or 6502A specification.  If a number is 
  179. followed by parenthesis, then it represents the delay, produced by TTL gates, 
  180. between the 6502 and the peripheral slots.  The characters in the parenthesis 
  181. denote the part number(s) of the part(s) which generated the delay.  These 
  182. parts are typically 74' series TTL except for the 8T28 and 8T97.  If there are 
  183. two numbers in a column with a plus sign (+) then the first number signifies 
  184. the 6502 specification and the second the TTL delay, with the corresponding 
  185. part number.  Most of the TTL delay times are from the Texas Instrument data 
  186. books.  The 6502 specifications are from the Synertek 6502 data sheet and from 
  187. Synertek application note AN2 - SY6500.
  188.  
  189.  
  190. When the RDY Line Can be Changed and When It Cannot
  191.  
  192. As can be seen from these figures, the RDY line should not be gated with the 
  193. PH0 trailing edge since this happens around the same time as the falling edge 
  194. of PH2.  This would violate the TRS specification and probably force the 6502 
  195. to perform erratically.  Gating the RDY line with the trailing edge of Q3 
  196. during PH0 might work, but this could leave as little as 25 ns for the signal 
  197. to be valid.  In other words, Q3 must enable the RDY line low within 25 ns of 
  198. Q3 changing states.  If this output cannot be guaranteed stable, then the RDY 
  199. line might violate the TRS specification.
  200.  
  201. The safest time to pull the RDY line is using the PH0 rising edge, but this 
  202. edge occurs before I/O SELECT, I/O STROBE, or DEVICE SELECT are enabled.  
  203. Therefore, this scheme will not work if any of these three enables is used by 
  204. the peripheral card.  For example, many peripheral cards use memory mapped I/O 
  205. to transfer data with the cards registers designed to reside in the DEVICE 
  206. SELECT memory space.  Location $C0n0 (where n = 8 + slot number of peripheral 
  207. card) might hold the status of the card, and location $C0n1 might be used to 
  208. read a device such as a disk or an A/D converter.  The card uses the DEVICE 
  209. SELECT signal, pin 41 on the slot, and the four low-order address lines to 
  210. determine if the 6502 wants to read the status register or read from the A/D 
  211. converter.  Typically, the status register can put its data on the bus within 
  212. 200 ns, easily meeting the setup requirements of the 6502.  But the A/D 
  213. converter might take at least 100 µs before it can respond with data.  The RDY 
  214. line must be pulled low to allow time for the A/D converter to set up the data 
  215. bus.  Notice that the peripheral card does not know that it should pull the 
  216. RDY line low until after the DEVICE SELECT signal has gone low.  This signal 
  217. does not go low until after PH0 goes high, so the PH0 rising edge cannot be 
  218. used to enable the RDY line for this peripheral card.
  219.  
  220. There are a few ways around this problem.  One solution would be to decode the 
  221. $C0n0 address on the peripheral card and not use DEVICE SELECT.  This solution 
  222. also requires either putting user-selectable switches on the card for setting 
  223. the slot number, or making the card slot dependent.  Another solution is to 
  224. pull the RDY line low using one of the first three edges, trailing or leading, 
  225. of the 7 M clock.  These edges occur at 70, 140, and 210 ns into PH0 and are 
  226. trailing, leading, then trailing edges, respectively.  The best solution is to 
  227. use the DEVICE SELECT signal to enable the RDY line.  Figure 2 should help.
  228.  
  229. 7M
  230. _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _
  231.  |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |
  232.  
  233. 0o
  234.     _____________               _____________               _____________
  235. ___|             |_____________|             |_____________|             |____
  236.  
  237. Q3
  238.     ______        ______        ______        ______        ______        ____
  239. ___|      |______|      |______|      |______|      |______|      |______|
  240.  
  241. DEVICE SELECT
  242. ____               _____________               _____________               ___
  243.     |_____________|             |_____________|             |_____________|
  244.  
  245.      write cycle                                   6502 halts with addresses &
  246.      don't pull RDY                                 R/W* line valid here
  247. ___________________  ____  ___________________________________________________
  248. ADDRESS R/W*       \/    \/ valid
  249. ___________________/\____/\___________________________________________________
  250.  
  251. RDY
  252. _____________________________________________
  253.      |<----+----->|                          |________________________________
  254.            |                                                 |<----+----->|
  255.            |                                                       |
  256.            |_______________________________________________________|
  257.                Do NOT change RDY line at these times
  258.  
  259.                          Figure 2 - Timing Diagram
  260.  
  261.  
  262. Do Not Pull RDY During Write Cycles
  263.  
  264. Because there is no acknowledge response from the 6502, the peripheral card 
  265. must do some of its own housekeeping and check if a write cycle is taking 
  266. place.  On write cycles, the 6502 will not halt, but continue running until 
  267. the next read cycle.  After a slow peripheral pulls the RDY line and before it 
  268. tries to get on the bus, it must make sure the 6502 is not in the middle of a 
  269. write cycle.  Otherwise there will be a bus crash, as both the peripheral card 
  270. and 6502 try to drive the bus.  One simple way to prevent this bus crash from 
  271. occurring is to make sure the peripheral card does not pull the RDY line low 
  272. during a write cycle.  You can guarantee this will not happen by checking the 
  273. R/W line when PH0 goes high or DEVICE SELECT goes low.  The R/W line is 
  274. guaranteed to be stable by this time.
  275.  
  276.  
  277. Releasing the RDY Line
  278.  
  279. When the RDY line is released, the 6502 will continue the cycle that was 
  280. originally halted and allow the 6502 to read the data bus.  Data will be read 
  281. on the next trailing edge of PH2 by the 6502, as long as RDY does not change 
  282. within TRS of the end of PH2.  When the peripheral device has set the data bus 
  283. up with the correct data, it can release the RDY line to complete the read 
  284. cycle.  Releasing the RDY line has exactly the same constraints as pulling the 
  285. line; do not change RDY within 200 ns of the end of PH2.
  286.  
  287. The RDY line can be released before data has been set up, if the data will be 
  288. valid within specification.  This means that RDY can be released in the middle 
  289. of PH1 if the data bus will be valid 117 ns before PH2 trailing edge, for the 
  290. Apple ][ (62 ns for the Apple IIe).
  291.  
  292.  
  293. Slow Writes
  294.  
  295. Since the 6502 cannot be halted during write cycles, if a device requires 
  296. longer than one cycle to receive data then the data must be buffered.  Here is 
  297. an example of how to accomplish this:
  298.  
  299.                              __________
  300.                             |          |
  301.                     _____|\ |     7    |_____|\ 
  302.           Data bus |       \|     4    |       \ to slow peripheral
  303.                    |_____  /|     L    |_____  /
  304.                          |/ |     S    |     |/ 
  305.                             |     3    |
  306.                             |     7    |
  307.           _____________     |     4    |
  308.           DEVICE SELECT     |  /\      |
  309.           or                |_/__\_____|
  310.           __________           |    O     ______
  311.           I/O SELECT  _________|    |___  INXFER
  312.           or
  313.           __________
  314.           I/O STROBE
  315.  
  316.                       Figure 3 - Buffering Data
  317.  
  318.  
  319. Note:    It is very easy to overrun the slow peripheral using this 
  320.          scheme, since it only buffers one byte at a time.  Do not send 
  321.          data twice to the buffer within the maximum allowed time between 
  322.          slow peripheral reads.
  323.  
  324.  
  325. Further Reference
  326.     o    Apple IIe Technical Reference Manual
  327.  
  328.